package com.example.spring_java_oj.mapper;

import com.example.spring_java_oj.model.Problem;
import org.apache.ibatis.annotations.*;


import org.springframework.stereotype.Controller;

import java.util.List;

@Mapper
public interface ProblemMapper {

    @Select("select * from oj_table where delete_flag = 1")
    public List<Problem> getProblems();

    @Select("select * from oj_table where id = #{id}")
    public Problem getProblem(Integer id);

    @Select("select id from oj_table where title = #{title} and description = #{description}")
    public Problem getProblemByName(@Param("title") String title, @Param("description") String description);

    //@Update("update blog set title=#{title}, content=#{content} where id=#{id}")
    @Update("update oj_table set title=#{title}, level=#{level}, description=#{description} " +
            "where id=#{id}")
    public Integer updateProblem(Problem problem);

    @Insert("insert into oj_table " +
            "values(null, #{title}, #{level}, #{description}, " +
            "#{templateCode}, #{testCode}, 1, #{answer}, 0)")
    public Integer insert(Problem problem);

    @Update("update oj_table set delete_flag = 0 where id=#{id}")
    public Integer delete(Integer id);


    @Update("update oj_table set finish = #{finish} where id = #{id}")
    void updateProblemAnswer(Problem problem);

    @Update("update oj_table set templateCode = #{templateCode} where id = #{id}")
    void updateTemCode(Problem problem);
}
